{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "from regression_tree import *"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "dataset = load_data('ex0.txt')\n",
    "tree = create_tree(dataset, fleaf, ferr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'feat_idx': 0,\n",
       " 'feat_val': 0.40015800000000001,\n",
       " 'left': {'feat_idx': 0,\n",
       "  'feat_val': 0.20819699999999999,\n",
       "  'left': -0.023838155555555553,\n",
       "  'right': 1.0289583666666666},\n",
       " 'right': {'feat_idx': 0,\n",
       "  'feat_val': 0.609483,\n",
       "  'left': 1.980035071428571,\n",
       "  'right': {'feat_idx': 0,\n",
       "   'feat_val': 0.81674199999999997,\n",
       "   'left': 2.9836209534883724,\n",
       "   'right': 3.9871631999999999}}}"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tree"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "dataset = np.array(dataset)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.collections.PathCollection at 0x109c20c50>"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAW4AAAD8CAYAAABXe05zAAAABHNCSVQICAgIfAhkiAA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xx1wHc5Pr+xu5tvvcRkQ3ofNz6f5mMLnk21wsR+TsAvgbgflW9nNHY0hB2vb8A4LMAvici\nP0MnJ3i0wAuUNr/fdwEcVdWWqv4UwP9BJ5AXkc31fhXAEQBQ1f8JYDM6PT2GldX/8SQMMnD/GYDP\niMjNIrIRncXHo577HAXwj7pf/xqA49pdBSig0OsVkXEA/x6doF3k/CcQcr2qeklVr1PV7aq6HZ2c\n/v2qOjeY4fbN5t/zLDqzbYjIdeikTn6S5SATZHO9FwD8KgCIyN9AJ3AvZTrKbB0F8A+71SV7AFxS\n1Z+n8koDXqXdh86s4y0AX+ve9nV0/gMDnV/0SwB+DOB/AfjFQY43g+v9rwD+L4CF7p+jgx5zmtfr\nue/3UOAjXupkAAAAeElEQVSqEsvfr6CTHvohgDMAvjzoMad8vbcCOIlOxckCgC8Mesx9Xu+LAH4O\noIXOp6evAvgtAL/l+v1+s/v3cSbNf8/cOUlEVDDcOUlEVDAM3EREBcPATURUMAzcREQFw8BNRFQw\nDNxERAXDwE1EVDAM3EREBfP/ATWTEFlkthKIAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x109b9d390>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.scatter(dataset[:, 0], dataset[:, 1])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 绘制树回归曲线"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[<matplotlib.lines.Line2D at 0x109cca748>]"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAD8CAYAAACMwORRAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAFhVJREFUeJzt3X2MXXWdx/H3h1JKkVIeOpTSdjogNdnKuoAjAppdVl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3JrS/vmid6n2vGPkLJu2VSfp9F9XTU88AzwIq8a56EfV4E/IZqJ81G4AN5\n19zi/v4Q2A68RvUvseuBzwCfGfU9vj3593gm659rX6FqZtaGinxaxszMmuRwNzNrQw53M7M25HA3\nM2tDDnczszbkcDcza0MOdzOzNuRwNzNrQ/8LfR/vUvqwLfQAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x109c6def0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "x = np.linspace(0, 1, 50)\n",
    "y = [tree_predict([i], tree) for i in x]\n",
    "plt.plot(x, y, c='r')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
